package com.wugz.app.service.impl;

import com.wugz.app.pojo.Article;
import com.wugz.app.repository.ArticleRepository;
import com.wugz.app.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Component;

/**
 * @ClassName ArticleServiceImpl
 * @Description
 * @Author wugz
 * @Date 2020/3/21 18:53
 * @Version 1.0
 */
@Component
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private ArticleRepository articleRepository;

    @Override
    public Page<Article> list(int page, int pageSize) {
        Sort sort = Sort.by(Sort.Direction.ASC,"id");
        Pageable pageable = PageRequest.of(page, pageSize, sort);
        Page<Article> articles = articleRepository.findAll(pageable);
        return articles;
    }
}
